package com.zzyl.nursing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.dto.MeberOrderProjectDto;
import com.zzyl.nursing.mapper.MemberOrdersProjectMapper;
import com.zzyl.nursing.service.IMemberOrdersProjectService;
import com.zzyl.serve.domain.NursingProject;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberOrdersProjectServiceImpl extends ServiceImpl<MemberOrdersProjectMapper, NursingProject> implements IMemberOrdersProjectService {

    @Override
    public TableDataInfo selectNursingProjectList(MeberOrderProjectDto dto) {
        IPage<NursingProject> page = new Page<>(dto.getPageNum(), dto.getPageSize());
        LambdaQueryWrapper<NursingProject> lambdaQueryWrapper = Wrappers.<NursingProject>lambdaQuery()
                .eq( dto.getStatus()!=null,NursingProject::getStatus, dto.getStatus())
                .like(dto.getName()!=null,NursingProject::getName, dto.getName());
            IPage<NursingProject> nursingProjectIPage = page(page, lambdaQueryWrapper);
        Integer total = Math.toIntExact(nursingProjectIPage.getTotal());
        List<NursingProject> nursingProjects = nursingProjectIPage.getRecords();
        return new TableDataInfo<>(nursingProjects,total);
    }
}
